﻿using DotNetMVC.Common;
using DotNetMVC.DTO;
using DotNetMVC.IService;
using DotNetMVC.Website.Areas.WebAdmin.Common;
using DotNetMVC.Website.Areas.WebAdmin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;

namespace DotNetMVC.Website.Areas.WebAdmin.Controllers
{
    public class SiteConfigController : Controller
    {
        public ISiteNavService siteNavService { get; set; }

        // GET: WebAdmin/SiteConfig
        [HttpGet]
        public ActionResult Index()
        {
            SiteConfigEditGetViewModel model = new SiteConfigEditGetViewModel();

            model.SiteConfig = AdminHelper.GetSiteConfig(ControllerContext);

            List<SelectListItem> listSiteNav = new List<SelectListItem>();
            foreach (SiteNavDTO dto in siteNavService.GetSiteNavsByLevel(2))
            {
                SelectListItem listItem = new SelectListItem();
                for (int i = 0; i < dto.NavLevel; i++)
                {
                    dto.NavName = "|-" + dto.NavName;
                }
                listItem.Text = dto.NavName;
                listItem.Value = dto.Id.ToString();
                listItem.Selected = false;
                listSiteNav.Add(listItem);
            }
            model.ListSiteNav = listSiteNav;

            return View(model);
        }



        [HttpPost]
        public ActionResult Edit(string sitename, string siteurl, string keywords, string description,
            string homebanner, string homeNotice, string homeNews, string homeAbout, string homeStudy,
            string headerlinks, string footerlinks, string address, string tel, string email, string copyright)
        {
            AdminHelper.SetSiteConfig(ControllerContext, sitename, siteurl, keywords, description,
                 homebanner, homeNotice, homeNews, homeAbout, homeStudy,
             headerlinks, footerlinks, address, tel, email, copyright);

            //清除底部缓存
            StaticPageHelper.ClearFooterCache(ControllerContext);

            //操作日志
            AdminHelper.AddUserLog(HttpContext, "修改网站配置");

            return Json(new AjaxResult { Status = "ok" });
        }
    }
}